#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2e5 + 5;
int n,m,x;


signed main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>x;
    for(int i=1;i<=m;i++)
        cin>>x;
    int k = 0;
    while(k ++)
        if(pow(2,k + 1) > n)
            break;
    for(int i=1;i<=k;i++)
        cin>>x;
    int T;
    cin>>T;
    while(T--){
        cout<<(1 + n) * n / 2<<endl;
    }
    return 0;
}
